package com.heiyu.api.controller;

import com.google.common.collect.Lists;
import com.heiyu.api.request.NoticeListRequest;
import com.heiyu.api.response.NoticeListResponse;
import com.heiyu.api.response.model.NoticeEntity;
import com.heiyu.api.response.model.NoticeListModel;
import com.heiyu.controller.ApiBaseController;
import com.heiyu.dao.SystemNoticeMapper;
import com.heiyu.entity.SystemNotice;
import com.heiyu.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "消息通知")
@RestController
@RequestMapping(value = "api/v1/notice")
public class NoticeSystsmController extends ApiBaseController {

    @Autowired
    private SystemNoticeMapper systemNoticeMapper;

    @ApiOperation(value = "list",notes = "消息列表")
    @RequestMapping(value = "list",method = RequestMethod.GET)
    public NoticeListResponse list(@ModelAttribute NoticeListRequest request){
        NoticeListResponse response = new NoticeListResponse();
        response.success();
        response.setData(new NoticeListModel());
        response.getData().setList(Lists.newArrayList());
        List<SystemNotice> list = this.systemNoticeMapper.selectList(new SystemNotice());
        if(!CollectionUtils.isEmpty(list)){
            NoticeEntity entity;
            for(SystemNotice notice:list){
                entity  = new NoticeEntity();
                entity.setContent(notice.getContent());
                entity.setTitle(notice.getTitle());
                entity.setCreatedTime(DateUtils.format(notice.getCreatedTime(),"yyyy/MM/dd HH:mm"));
                response.getData().getList().add(entity);
            }
        }
        return response;
    }


    @ApiOperation(value = "doc",notes = "消息推送说明")
    @GetMapping(value = "doc")
    public Object get(){
        return "APP schema 配置 开发优先级按照排列顺序\n" +
                "H5 正常的外链跳转（schema://heiyu.com/app/h5?url=*********）\n" +
                "资讯详情 外链地址 （schema://heiyu.com/information/detail?articleId=*******）\n" +
                "行情详情 内部地址 （schema://heiyu.com/market/detail?type=**&targetId=***）三级行情详情页\n" +
                "快讯模块 内部地址 （schema://heiyu.com/information/module）\n" +
                "币学堂模块 内部地址 （schema://heiyu.com/coinSchool/module）\n" +
                "币论模块 内部地址 （schema://heiyu.com/coinDiscuss/module）\n" +
                "大咖说 内部地址 （schema://heiyu.com/author?authorId=***）";
    }
}
